package com.eling.elcms.travel.webapp.controller;

import com.eling.elcms.core.dao.hibernate.search.SearchCondition;
import com.eling.elcms.core.webapp.controller.BaseFormController;
import com.eling.elcms.core.webapp.controller.Msg;
import com.eling.elcms.travel.model.ChangeRoom;
import com.eling.elcms.travel.model.TravelContract;
import com.eling.elcms.travel.model.WelfareConsumptionCoupon;
import com.eling.elcms.travel.model.WelfareConsumptionCouponDetail;
import com.eling.elcms.travel.model.view.ChangeRoomDetailView;
import com.eling.elcms.travel.model.view.ChangeRoomView;
import com.eling.elcms.travel.model.view.WelfareConsumptionCouponStatisticsView;
import com.eling.elcms.travel.model.view.WelfareConsumptionCouponView;
import com.eling.elcms.travel.service.IChangeRoomManager;
import com.eling.elcms.travel.service.IWelfareConsumptionCouponDetailManager;
import com.eling.elcms.travel.service.IWelfareConsumptionCouponManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;
@Controller
public class WelfareConsumptionCouponController extends BaseFormController{
	
	@Autowired
	private IWelfareConsumptionCouponManager welfareConsumptionCouponManager;
	
	@Autowired
	private IChangeRoomManager changeRoomManager;
	
	@Autowired
	private IWelfareConsumptionCouponDetailManager welfareConsumptionCouponDetailManager;
	
	@RequestMapping("/api/welfareconsumptioncoupon/saveall")
	@ResponseBody
	public WelfareConsumptionCoupon saveAll(
			@RequestParam(value="pkWelfarecc") Long pkWelfarecc,
			@RequestParam(value="price") Double price,
			@RequestParam(value="remarkDetail") String remarkDetail) {
		return welfareConsumptionCouponManager.saveAll(pkWelfarecc,price,remarkDetail);
	}

	@RequestMapping("/api/welfareconsumptioncoupon/{pkWelfareConsumptionCoupon}/deleteall")
	@ResponseBody
	public Msg delete(@PathVariable Long pkWelfareConsumptionCoupon) {
		welfareConsumptionCouponManager.remove(pkWelfareConsumptionCoupon);
		return new Msg("删除成功");
	}

	@RequestMapping("/api/welfareconsumptioncoupon/queryall")
	@ResponseBody
	public List<WelfareConsumptionCouponDetail> queryAll(@ModelAttribute WelfareConsumptionCoupon cond,
			@RequestParam(value="flag") Boolean flag) {
		return welfareConsumptionCouponManager.queryAll(cond,flag);
	}

	@RequestMapping("/api/welfareconsumptioncoupon/searchall")
	@ResponseBody
	public List<WelfareConsumptionCoupon> search(@ModelAttribute SearchCondition sc,
			@ModelAttribute WelfareConsumptionCoupon cond) {
		sc.setQueryCondition(cond);
		return welfareConsumptionCouponManager.search(sc);
	}
	
	@RequestMapping("/api/welfareconsumptioncoupon/queryrule")
	@ResponseBody
	public Double queryRule(@ModelAttribute WelfareConsumptionCoupon cond) {
		return welfareConsumptionCouponManager.queryRule(cond);
	}
	
	/**
	 *  查询待发放消费券的会员
	 * @param date
	 * @return
	 * @author ly
	 */
	@RequestMapping("/api/welfareconsumptioncoupon/querywelfarecard")
	@ResponseBody
	public List<WelfareConsumptionCouponView> queryWelfareCard(@ModelAttribute Date date){
		return welfareConsumptionCouponManager.queryWelfareCard(date);
	}
	
	/**
	 *  查询消费券的会员
	 * @param date
	 * @return
	 * @author ly
	 */
	@RequestMapping("/api/welfareconsumptioncoupon/querywelfare")
	@ResponseBody
	public List<WelfareConsumptionCoupon> queryWelfare(@ModelAttribute WelfareConsumptionCoupon cond){
		return welfareConsumptionCouponManager.query(cond);
	}
	
	/**
	 *  验证卡号是否已经被使用
	 * @return
	 * @author ly
	 */
	@RequestMapping("/api/welfareconsumptioncoupon/querycard")
	@ResponseBody
	public Integer queryWelfareCardAjax(String cardNo){
		return welfareConsumptionCouponManager.queryWelfareCardAjax(cardNo);
	}
	
	/*发卡*/
	@RequestMapping("/api/welfareconsumptioncoupon/savecard")
	@ResponseBody
	public WelfareConsumptionCoupon saveCard(@ModelAttribute WelfareConsumptionCoupon welfareConsumptionCoupon) {
		return welfareConsumptionCouponManager.saveCard(welfareConsumptionCoupon);
	}
	
	@RequestMapping("/api/welfareconsumptioncoupon/search*")
	@ResponseBody
	public List<WelfareConsumptionCouponView> sreach(@ModelAttribute SearchCondition sc) {
		return welfareConsumptionCouponManager.queryWelfareCardSerarch(sc);
	}
	
	@RequestMapping("/api/welfareconsumptioncoupon/searchwel")
	@ResponseBody
	public List<WelfareConsumptionCoupon> searchGrid(@ModelAttribute SearchCondition sc,WelfareConsumptionCoupon cond) {
		return welfareConsumptionCouponManager.queryWelfareCardSerarchGrid(sc,cond);
	}
	
	/*取现*/
	@RequestMapping("/api/welfareconsumptioncoupondetail/enchashment")
	@ResponseBody
	public WelfareConsumptionCouponDetail save(@ModelAttribute WelfareConsumptionCouponDetail cond) {
		return welfareConsumptionCouponDetailManager.saveEnchashment(cond);
	}
	
	/*挂失*/
	@RequestMapping("/api/welfareconsumptioncoupondetail/loss")
	@ResponseBody
	public WelfareConsumptionCouponDetail saveGS(@ModelAttribute WelfareConsumptionCouponDetail cond) {
		return welfareConsumptionCouponDetailManager.saveLoss(cond);
	}
	
	/*退卡*/
	@RequestMapping("/api/welfareconsumptioncoupondetail/returncard")
	@ResponseBody
	public WelfareConsumptionCouponDetail savereturnCard(@ModelAttribute WelfareConsumptionCouponDetail cond) {
		return welfareConsumptionCouponDetailManager.saveReturnCard(cond);
	}
	
	/*补办*/
	@RequestMapping("/api/welfareconsumptioncoupon/postregistered")
	@ResponseBody
	public WelfareConsumptionCoupon postregistered(@ModelAttribute WelfareConsumptionCoupon cond) {
		return welfareConsumptionCouponManager.postregistered(cond);
	}
	/**
	 * 
	 * 换房调整
	 */
	@RequestMapping("/api/changeroom/querygroup")
	@ResponseBody
	public List<ChangeRoomView> queryGroup(@ModelAttribute ChangeRoomView cond){
		return changeRoomManager.queryGroup(cond);
	}
	
	/**
	 * 
	 * 换房调整详情
	 */
	@RequestMapping("/api/changeroom/querydetail")
	@ResponseBody
	public List<ChangeRoomView> queryGroupDetail(@ModelAttribute ChangeRoomView cond){
		return changeRoomManager.queryGroupDetail(cond);
	}
	
	/**
	 * 
	 * 换房调整详情
	 */
	@RequestMapping("/api/changeroom/saveall")
	@ResponseBody
	public List<ChangeRoom> save(@ModelAttribute ChangeRoomDetailView cond){
		return changeRoomManager.saveAll(cond);
	}
	
	@RequestMapping("/api/changeroom/save")
	@ResponseBody
	public ChangeRoom save(@ModelAttribute ChangeRoom cond){
		return changeRoomManager.save(cond);
	}
	
	/**
	 * TODO 待建立新的changeroomcontroller
	 * @param cond
	 * @return
	 */
	@RequestMapping("/api/changeroom/query")
	@ResponseBody
	public List<ChangeRoom> query(@ModelAttribute ChangeRoom cond){
		return changeRoomManager.query(cond);
	}
	
	@RequestMapping("/api/changeroom/ajaxroomcode")
	@ResponseBody
	public String ajaxRoomCode(ChangeRoomView cond){
		return changeRoomManager.ajaxRoomCode(cond);
	}
	
	/**
	 * 根据联系人搜索
	 */
	@RequestMapping("/api/changeroom/searchname")
	@ResponseBody
	public List<ChangeRoomView> searchname(@ModelAttribute ChangeRoomView cond){
		return changeRoomManager.searchname(cond);
	}
	
	/**
	 * 查询消费卷统计
	 * @param pkWelfarecc
	 * @return
	 */
	@RequestMapping("/api/welfareconsumptioncoupon/querystatistics")
	@ResponseBody
	public List<WelfareConsumptionCouponStatisticsView> queryStatistics(@ModelAttribute TravelContract cond){
		return welfareConsumptionCouponManager.queryStatistics(cond);
	}
}
